package com.dingreading.cloud.app.service.impl;

import com.dingreading.cloud.app.entity.StoreAndroid;
import com.dingreading.cloud.app.entity.table.StoreAndroidTableDef;
import com.dingreading.cloud.app.mapper.StoreAndroidMapper;
import com.dingreading.cloud.app.service.StoreAndroidService;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.update.UpdateChain;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2023-11-22
 */
@Service
public class StoreAndroidServiceImpl extends BaseServiceImpl<StoreAndroidMapper, StoreAndroid, StoreAndroidTableDef> implements StoreAndroidService {

    @Override
    protected StoreAndroidTableDef getTable() {
        return StoreAndroidTableDef.storeAndroid;
    }

    @Override
    public long getByStoreUidAndDeviceIdCnt(String storeUid, String deviceId) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.storeUid.eq(storeUid))
                .and(table.deviceId.eq(deviceId));

        return getMapper().selectCountByCondition(condition);
    }

    @Override
    public void updateInfo(String storeUid, String storeName, String deviceId, Integer versionCode, String ip, Date loginTime) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.storeUid.eq(storeUid))
                .and(table.deviceId.eq(deviceId));
        UpdateChain.of(StoreAndroid.class)
                .set(table.storeName, storeName)
                .set(table.versionCode, versionCode)
                .set(table.loginTime, loginTime)
                .set(table.ip, ip)
                .where(condition)
                .update();
    }
}
